﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Text;
using System.Windows.Forms;
using MediaPortal.GUI.Library;

public class GUISkypeVideo : GUIControl
{

  #region Construction

  private GUISkypeVideo() { }

  public GUISkypeVideo(int nParentID)
    : base(nParentID) { }

  public GUISkypeVideo(int dwParentID, int dwControlId, int dwPosX, int dwPosY, int dwWidth, int dwHeight)
    : base(dwParentID, dwControlId, dwPosX, dwPosY, dwWidth, dwHeight)
  {
    _imageWidth = 0;
    _imageHeight = 0;
    FinalizeConstruction();
  }

  public override void FinalizeConstruction()
  {
    base.FinalizeConstruction();
  }

  #endregion Construction

  public Image MemoryImage
  {
    get { return _memoryImage; }
    set { _memoryImage = value; }
  }

  public override void AllocResources()
  {
    base.AllocResources();
    //blackImage.AllocResources();
  }

  public override void FreeResources()
  {
    base.FreeResources();
    //blackImage.FreeResources();
  }

  public override void OnDeInit()
  {
    GUIGraphicsContext.VideoWindow = new Rectangle(0, 0, 0, 0);
    base.OnDeInit();
  }

  public override void OnInit()
  {
    base.OnInit();

    float x = base.XPosition;
    float y = base.YPosition;
    GUIGraphicsContext.Correct(ref x, ref y);

  }

  public override void Render(float timePassed)
  {
/*
    if (GUIGraphicsContext.EditMode == false)
    {
      if (!IsVisible)
      {
          GUIGraphicsContext.VideoWindow = new Rectangle(0, 0, 0, 0);
        base.Render(timePassed);
        return;
      }
    }
*/
    if (!GUIGraphicsContext.Calibrating)
    {
      float x = base.XPosition;
      float y = base.YPosition;
      GUIGraphicsContext.Correct(ref x, ref y);

      if (GUIGraphicsContext.ShowBackground)
      {

        if (GUIGraphicsContext.graphics != null)
        {
          //GUIGraphicsContext.graphics.FillRectangle(Brushes.Black, _videoWindows[0].X, _videoWindows[0].Y, base.Width,
          //                                          base.Height);
        }
        else
        {
          //image.SetPosition(_videoWindows[0].X,_videoWindows[0].Y);
          //image.Width=_videoWindows[0].Width;
          //image.Height=_videoWindows[0].Height;
            //blackImage.MemoryImage = m_pictureBox.Image;
            //blackImage.RenderOpen();
            //blackImage.Render(timePassed); // causes flickering in fullscreen
            //GUIGraphicsContext.graphics.DrawImage(m_image, 10,10);
          // gibman ; without the above line we get this bug instead mantis# 1069
          //GUIGraphicsContext.DX9Device.Clear( ClearFlags.Target|ClearFlags.Target, Color.FromArgb(255,1,1,1), 1.0f, 0,_videoWindows);
        }
      }
      else
      {
        if (GUIGraphicsContext.graphics != null)
        {
          //GUIGraphicsContext.graphics.FillRectangle(Brushes.Black, _videoWindows[0].X, _videoWindows[0].Y, base.Width,
          //                                          base.Height);
        }
      }
    }
    base.Render(timePassed);
  }




  public Image Image
  {
    get { return m_image; }
    set
    {
      //m_pictureBox.Height = value.Height;
      //m_pictureBox.Width = value.Width;
      //m_pictureBox.Image = value;
    }
  }

}
